package com.yupi.usercenter.feign.client;

import com.alibaba.fastjson.JSON;
import com.yupi.usercenter.base.model.Result;
import com.yupi.usercenter.basic.vo.SqNetworkPageVO;
import com.yupi.usercenter.common.ResultUtils;
import com.yupi.usercenter.feign.hystrix.SqNetworkFeignClientHystrix;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * 云路供应链科技有限公司 版权所有 © Copyright 2020
 * <p>
 * 调用lmdm的工具类
 *
 * @author 沈昱
 * @version 1.0.0
 * @date Created in 2020/8/24
 */
@Slf4j
@Component
public class LmdmClientHelper {

    @Autowired
    private SqNetworkFeignClientHystrix sqNetworkFeignClientHystrix;

    public SqNetworkPageVO getNetworkById(int networkId) {
        LocalDateTime startTime = LocalDateTime.now();
        log.info("远程请求，基础资料-根据网点id查询网点信息 -> 开始时间:{}, 请求参数:{}", startTime.toString(), networkId);
        Result<SqNetworkPageVO> result = sqNetworkFeignClientHystrix.getNetworkById(networkId);
        ResultUtils.checkRemoteResult(result);
        LocalDateTime endTime = LocalDateTime.now();
        SqNetworkPageVO sqNetworkPageVO = result.getData();
        log.info("远程请求，基础资料-根据网点id查询网点信息 -> 结束时间:{}, 耗时(毫秒):{}, 返回结果:{}", endTime.toString(), Duration.between(startTime, endTime).toMillis(), JSON.toJSONString(sqNetworkPageVO));
        return sqNetworkPageVO;
    }

}
